package com.api;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;


public class ApiUtils {
	
	
    static final String url ="https://api.realtimecat.com";
    private static HttpClientUtil httpClientUtil = null; 
	static {
		  httpClientUtil = new HttpClientUtil();  
	}
	/**
	 * 
	 * 方法名：createSession
	 * 功能描述: 创建房间
	 *
	 * @return
	 * @throws JsonParseException
	 * @throws JsonMappingException
	 * @throws IOException
	 *
	 * 作者： 超哥
	 * 创建时间： 2016年8月19日 下午2:42:26
	 *
	 */
	public static String createSession() throws JsonParseException, JsonMappingException, IOException{
		String httpOrgCreateTest = url+"/v0.3/sessions";  
        Map<String,String> createMap = new HashMap<String,String>();  
        createMap.put("type","p2p");  
        createMap.put("label","程序创建session");  
        createMap.put("permanent","false");  
        createMap.put("live_days","1");  
        String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,createMap);  
        
        ObjectMapper mapper = new ObjectMapper();
        Map<String, String> map =  mapper.readValue(httpOrgCreateTestRtn, Map.class);
        return map.get("uuid");
	}
	
	/**
	 * 
	 * 方法名：createToken
	 * 功能描述: 创建token
	 *
	 * @return
	 * @throws JsonParseException
	 * @throws JsonMappingException
	 * @throws IOException
	 *
	 * 作者： 超哥
	 * 创建时间： 2016年8月19日 下午2:42:10
	 *
	 */
	public static String createToken() throws JsonParseException, JsonMappingException, IOException{
		String httpOrgCreateTest = url+"/v0.3/sessions/147a45f5-6f2b-4251-879d-4bd14acf21b0/tokens";  
        Map<String,String> createMap = new HashMap<String,String>();  
        createMap.put("type","pub");  
        createMap.put("label","程序创建Token");  
        createMap.put("permanent","false");  
        createMap.put("live_days","1");  
        createMap.put("number","1");  
        String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,createMap);  
        
        ObjectMapper mapper = new ObjectMapper();
        Map<String, String> map =  mapper.readValue(httpOrgCreateTestRtn, Map.class);
        return map.get("uuid");
		
	}

}
